package top.hcode.hoj.controller.org;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.hcode.hoj.common.exception.StatusFailException;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.manager.org.OrgUserManager;
import top.hcode.hoj.pojo.dto.OrgUserLoginDTO;
import top.hcode.hoj.pojo.vo.UserInfoVO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author orangej
 * @since 2025/1/21
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class OrgUserController {
    private final OrgUserManager orgUserManager;

    @ApiOperation(value = "学生/教师登录")
    @PostMapping("/org-user/login")
    public CommonResult<UserInfoVO> login(@Validated @RequestBody OrgUserLoginDTO orgUserLoginDTO, HttpServletRequest request, HttpServletResponse response) throws StatusFailException {
        return CommonResult.successResponse(orgUserManager.login(orgUserLoginDTO, request, response));
    }

    @ApiOperation(value = "学生/教师退出登录")
    @PostMapping("/org-user/logout")
    public CommonResult<Void> logout() {
        orgUserManager.logout();
        return CommonResult.successResponse();
    }
}
